<template>
  <!-- <div
    class="login flex-column flex-justify-center flex-align-center m0 b0">

    <p class="fz35 pb50" style="color: #2d8cf0">Cloud API Demo</p>
    <a-form
      layout="inline"
      :model="formState"
      class="flex-row flex-justify-center flex-align-center"
    >
      <a-form-item>
        <a-input v-model:value="formState.username" placeholder="Username">
          <template #prefix
            ><UserOutlined style="color: rgba(0, 0, 0, 0.25)"
          /></template>
</a-input>
</a-form-item>
<a-form-item>
  <a-input v-model:value="formState.password" type="password" placeholder="Password">
    <template #prefix><LockOutlined style="color: rgba(0, 0, 0, 0.25)"
          /></template>
  </a-input>
</a-form-item>
<a-form-item>
  <a-button class="m0" type="primary" html-type="submit" :disabled="loginBtnDisabled" @click="onSubmit">
    Login1
  </a-button>
</a-form-item>
</a-form>
</div> -->
  <div class="login">
    <div class="login-content">
      <div class="login-content-left">
        <div class="login-content-left-logo">
          <img class="ant-image-img" src="/src/assets/icons/dji_logo.png" style="width:100px;">
          让每个节点都有计算能力
        </div>
        <div class="login-content-left-txt">welcome</div>
      </div>
      <div class="login-content-right">
        <div class="login-content-right-title">登录</div>
        <div class="login-content-right-form">
          <a-form :model="formState" layout="vertical">
            <a-form-item label="账号">
              <a-input size="large" v-model:value="formState.username" placeholder="Username">
                <template #prefix>
                  <UserOutlined style="color: rgba(0, 0, 0, 0.25)" />
                </template>
              </a-input>
            </a-form-item>
            <a-form-item label="密码">
              <a-input size="large" visibilityToggle v-model:value="formState.password" type="password"
                placeholder="Password">
                <template #prefix>
                  <LockOutlined style="color: rgba(0, 0, 0, 0.25)" />
                </template>
              </a-input>
            </a-form-item>
            <a-form-item>
              <!-- 忘记密码 -->
            </a-form-item>
            <a-form-item>
              <a-button class="m0" type="primary" html-type="submit" :disabled="loginBtnDisabled" @click="onSubmit"
                size="large" block>
                登录
              </a-button>
            </a-form-item>
          </a-form>
        </div>
      </div>
    </div>
  </div>
</template>

<script lang="ts" setup>
import djiLogo from '/@/assets/icons/dji_logo.png'
import { LockOutlined, UserOutlined } from '@ant-design/icons-vue'
import { message } from 'ant-design-vue'
import { reactive, computed, UnwrapRef } from 'vue'
import { login, LoginBody } from '/@/api/manage'
import { getRoot } from '/@/root'
import { ELocalStorageKey, ERouterName, EUserType } from '/@/types'
import router from '/@/router'

const root = getRoot()

const formState: UnwrapRef<LoginBody> = reactive({
  username: 'adminPC',
  password: 'adminPC',
  flag: EUserType.Web,
})

const loginBtnDisabled = computed(() => {
  return !formState.username || !formState.password
})

const onSubmit = async (e: any) => {
  const result = await login(formState)
  if (result.code === 0) {
    localStorage.setItem(ELocalStorageKey.Token, result.data.access_token)
    localStorage.setItem(ELocalStorageKey.WorkspaceId, result.data.workspace_id)
    localStorage.setItem(ELocalStorageKey.Username, result.data.username)
    localStorage.setItem(ELocalStorageKey.UserId, result.data.user_id)
    localStorage.setItem(ELocalStorageKey.Flag, EUserType.Web.toString())
    root.$router.push(ERouterName.WORKSPACE)
    // root.$router.push(ERouterName.WORKSPACE)
  } else {
    message.error(result.message)
  }
}

</script>

<style lang="scss" scoped>
.login {
  background-color: $dark-highlight;
  height: 100vh;
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;

  &::before {
    content: " ";
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-image: url(/src/assets/images/login-bg.png);
    background-position: center;
    background-repeat: no-repeat;
    background-size: cover;
  }

  &-content {
    width: 700px;
    display: flex;
    z-index: 1;
    border-radius: 4px;
    overflow: hidden;

    &-left {
      flex: 1;
      background-image: linear-gradient(to top right, #0d55b5, rgba(13, 85, 181, 0));
      display: flex;
      flex-direction: column;
      color: #fff;

      &-logo {
        flex: 2;
        display: flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 20px;
        letter-spacing: 2px;
      }

      &-txt {
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: center;
        font-family: 'Vibur';
        font-size: 25.09px;
        font-weight: normal;
        line-height: normal;
        letter-spacing: 0px;
      }
    }

    &-right {
      flex: 1;
      background: #fff;

      &-title {
        margin-top: 30px;
        font-size: 20px;
        text-align: center;
        font-weight: bold;
        letter-spacing: 4px;
        color: rgba(0, 0, 0, .8)
      }

      &-form {
        padding: 10px 40px 20px;
      }
    }
  }
}
</style>
